//jsconfig end
</script>

<script>
//core js here

var inhibitOnclick;
var g_currentParentDir;
var g_currentViewExpander;
var g_currentDownloadUri;
var g_openedNodeInfo;

function init(){
	g_currentParentDir = document.createElement( "div" );
	g_currentParentDir.className = "rootNode";
	g_currentViewExpander = document.getElementById( "rootExpander" );
}

function bodyOnclick(){
	inhibitOnclick = false;
}

function createXMLHTTPRequest(){
	try{ return new XMLHttpRequest();                      } catch( e ){}
	try{ return new ActiveXObject( "Msxml2.XMLHTTP.6.0" ); } catch( e ){}
	try{ return new ActiveXObject( "Msxml2.XMLHTTP.3.0" ); } catch( e ){}
	try{ return new ActiveXObject( "Msxml2.XMLHTTP"     ); } catch( e ){}
	try{ return new ActiveXObject( "Microsoft.XMLHTTP"  ); } catch( e ){}
	return null;
}

function _nodeLoadNodes( msg, request, downloadUri ){
	if( request.readyState != 4 ) return;
	//0 on error or request.abort();
	if( request.status != 200 ){
		msg.innerHTML = "Load failed. Request status: " + request.status + ".";
		return;
	}
	g_currentDownloadUri = downloadUri;
	eval( request.responseText );
	
	msg.innerHTML = "<input type=\"button\" value=\" ../ \" onclick=\"dirOut();\">";
}

function nodeLoadNodes(){
	
	var i;
	var found;
	var jumpNode;
	var downloadUri;
	var requestPath;
	var request = createXMLHTTPRequest();
	var msg = document.createElement( "div" );
	g_currentViewExpander.appendChild( msg );
	if( !request ){
		msg.innerHTML = "Browser does not support XHR.";
		return;
	}
	jumpNode = g_currentParentDir;
	requestPath = "";
	do{
		found = null;
		//read id and add to path
		for( i = 0; i < jumpNode.childNodes.length; i++ ){
			if( jumpNode.childNodes[i].className == "_dirId" ){
				found = jumpNode.childNodes[i].value;
				break;
			}
		}
		//found check
		if( !found ){
			msg.innerHTML = "HTML error: missing dirId.";
			return;
		}
		requestPath = "/" + found + requestPath;
		//to root or expander
		jumpNode = jumpNode.parentNode;
		if( jumpNode.className != "dirExpander" ){
			msg.innerHTML = "HTML error: missing dirExpander.";
			return;
		}
		jumpNode = jumpNode.parentNode;
	}while( jumpNode.className == "nodeListItem" );
	
	//if not root, then error
	if( jumpNode.className != "rootNode" ){
		msg.innerHTML = "HTML error: missing rootNode.";
		return;
	}
	
	downloadUri = "download" + requestPath;
	requestPath = "nodeinfo" + requestPath;
	msg.innerHTML = "Loading...";
	request.open( "GET", requestPath, true );
	request.onreadystatechange = function(){ _nodeLoadNodes( msg, request, downloadUri ); };
	request.send();
}

function dirIn( el ){
	if( inhibitOnclick ) return;
	inhibitOnclick = true;
	var currentDir = el.parentNode;
	var i;
	var childs = currentDir.childNodes;
	var expander;
	for( i = 0; i < childs.length; i++ ){
		if( childs[i].className == "dirExpander" ){
			expander = childs[i];
			break;
		}
	}
	if( !expander ) return;
	
	document.getElementById( "fileBrowserHeader" ).innerHTML = "Index of " + el.innerHTML;
	
	g_currentParentDir.appendChild( g_currentViewExpander );
	g_currentViewExpander.style.display = "none";
	expander.style.display = "block";
	document.getElementById( "fileBrowser" ).appendChild( expander );
	g_currentParentDir = currentDir;
	g_currentViewExpander = expander;
	if( !expander.hasChildNodes() ) nodeLoadNodes();
}

function dirOut(){
	if( inhibitOnclick ) return;
	inhibitOnclick = true;
	var i;
	var expander = g_currentParentDir.parentNode;
	var parentDir = expander.parentNode;
	var childs;
	
	if( parentDir.className == "rootNode" ){
		document.getElementById( "fileBrowserHeader" ).innerHTML = "Shared content";
	} else {
		childs = parentDir.childNodes;
		for( i = 0; i < childs.length; i++ ){
			if( childs[i].className != "dirName" ) continue;
			document.getElementById( "fileBrowserHeader" ).innerHTML = "Index of " + childs[i].innerHTML;
			break;
		}
	}
	
	g_currentParentDir.appendChild( g_currentViewExpander );
	g_currentViewExpander.style.display = "none";
	expander.style.display = "block";
	document.getElementById( "fileBrowser" ).appendChild( expander );
	g_currentParentDir = parentDir;
	g_currentViewExpander = expander;
}

function showNodeInfo( el ){
	if( inhibitOnclick ) return;
	inhibitOnclick = true;
	var i;
	var childs = el.childNodes;
	
	for( i = 0; i < childs.length; i++ ){
		if( childs[i].className != "nodeInfoBlock" ) continue;
		if( g_openedNodeInfo == childs[i] ) break;
		if( g_openedNodeInfo ) g_openedNodeInfo.style.display = "none";
		childs[i].style.display = "block";
		g_openedNodeInfo = childs[i];
		break;
	}
}

function customCreateElement( elTag, elClass, elInnerHTML ){
	var el = document.createElement( elTag );
	el.className = elClass;
	el.innerHTML = elInnerHTML;
	return el;
}

function createDlLink( href, text ){
	var link = document.createElement( "a" );
	link.className = "nodeInfoLink";
	link.href = href + "/" + text;
	link.href = href;
	link.target = "_blank";
	link.innerHTML = text;
	return link;
}

function generateDlLinkBox( node, nodeType, uri ){
	var i;
	var link;
	var space;
	
	if( nodeType > 6 && hasRaw ){ //if common file
		if( hasFile ){
			link = createDlLink( uri + "/view", "open" );
			node.appendChild( link );
			space = document.createTextNode( " " );
			node.appendChild( space );
		}
		
		link = createDlLink( uri + "/", "raw" );
		node.appendChild( link );
		space = document.createTextNode( " " );
		node.appendChild( space );
		for( i = 0; avaliableCompressors[i]; i++ ){
			link = createDlLink( uri + "/" + avaliableCompressors[i], "." + avaliableCompressors[i] );
			node.appendChild( link );
			space = document.createTextNode( " " );
			node.appendChild( space );
		}
	}
	
	if( hasTar ){
		link = createDlLink( uri + "/" + "tar", ".tar" );
		node.appendChild( link );
		space = document.createTextNode( " " );
		node.appendChild( space );
		for( i = 0; avaliableCompressors[i]; i++ ){
			link = createDlLink( uri + "/tar." + avaliableCompressors[i], ".tar." + avaliableCompressors[i] );
			node.appendChild( link );
			space = document.createTextNode( " " );
			node.appendChild( space );
		}
	}
}

//create tree node
function cn( nodeType, nodeId, nodeName, nodeSize ){
	
	var node = document.createElement( "div" );
	node.className = "nodeListItem";
	node.onclick = function(){ showNodeInfo( this ); };
	g_currentViewExpander.appendChild( node );
	
	var nodeInfoBlock = document.createElement( "div" );
	nodeInfoBlock.className = "nodeInfoBlock";
	nodeInfoBlock.style.display = "none";
	
	var nodeInfoText = document.createElement( "textarea" );
	nodeInfoText.className = "nodeInfoText";
	nodeInfoText.readOnly = true;
	nodeInfoText.rows = 2;
	nodeInfoText.innerHTML = "Total size: " + readableSize( nodeSize );
	nodeInfoBlock.appendChild( nodeInfoText );
	
	generateDlLinkBox( nodeInfoBlock, nodeType, g_currentDownloadUri + "/" + nodeId );
	
	//if dir is empty
	if( !nodeType ){
		var p = document.createElement( "p" );
		p.innerHTML = "<center>(empty)</center>";
		g_currentViewExpander.appendChild( p );
		return;
	}
	
	var nodeSizeBlock = customCreateElement( "small", "nodeSize", " (" + readableSize(nodeSize) + ")" );
	
	//if node type is dir
	if( nodeType == 1 ){
		var inputDirId = document.createElement( "input" );
		inputDirId.type = "hidden";
		inputDirId.className = "_dirId";
		inputDirId.value = nodeId;
		node.appendChild( inputDirId );
		
		var dirName = customCreateElement( "span", "dirName", nodeName );
		dirName.onclick = function(){ dirIn( this ); };
		node.appendChild( dirName );
		
		node.appendChild( nodeInfoBlock );
		
		var expanderDiv = document.createElement( "div" );
		expanderDiv.className = "dirExpander";
		node.appendChild( expanderDiv );
		
		return;
	}
	
	//if node type not dir
	var fileName = customCreateElement( "span", "fileName", nodeName );
	node.appendChild( fileName );
	node.appendChild( nodeInfoBlock );
}

function readableSize( bytes ){
	var i;
	var strArr = [ "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", null ];
	if( bytes < 1024 ) return bytes + " B";
	for( i = 0; bytes > 1023 && strArr[i+1]; i++ ) bytes /= 1024;
	return bytes.toFixed( 2 ) + strArr[i];
}

</script>

<style>
* ::-webkit-scrollbar {
	display: block;
}

* ::-webkit-scrollbar-thumb {
	background: #4c5158;
}

* ::-webkit-scrollbar-thumb:hover {
	background: #666666;
}

* ::-webkit-scrollbar-thumb:active {
	background: #888888;
}

* {
	scrollbar-color: #4c5158 #ffffff;
}

.fileBrowserHeader {
	color: #ffffff;
	background: #4c5158;
	margin-left:  10%;
	margin-right: 10%;
	padding-left: 2%;
	line-height:  35pt;
	font-size:    16pt;
	word-wrap: break-word;
	border-top-left-radius:  3pt;
	border-top-right-radius: 3pt;
}

.fileBrowser {
	margin-left:  10%;
	margin-right: 10%;
	border: #4c5158 solid 1pt;
	background: #f6f8fa;
	border-bottom-left-radius:  3pt;
	border-bottom-right-radius: 3pt;
}

.nodeListItem {
	line-height: 28pt;
	border-top: 1pt solid #dadada;
}

.nodeListItem:hover {
	background: #ffffff;
}

.dirName:before {
	margin: 0 6pt 0 5pt;
	content: url( "" );
}

.fileName:before {
	margin: 0 7pt 0 7pt;
	content: url( "" );
}

.dirName {
	margin-left: 6pt;
	color: #57606a;
	font-weight: bold;
	word-wrap: break-word;
	cursor: pointer;
}

.fileName {
	margin-left: 6pt;
	word-wrap: break-word;
	color: #57606a;
}

.nodeInfoLinkBox {
	float: right;
	margin-right: 2%;
}

.nodeInfoLink {
	color: #57606a;
	cursor: pointer;
	text-decoration: none;
	padding: 2pt 4pt;
	border: 1pt solid #4c5158;
	border-radius: 3pt;
	font-weight: bold;
	font-size: 10px;
}

.nodeInfoBlock {
	margin-left: 2%;
	margin-right: 2%;
}

.nodeInfoText {
	border: none;
	background-color: transparent;
	width: 100%;
	white-space: pre;
	resize: none;
}

.about {
	margin-left: 10%;
	margin-right: 10%;
	color: #24292f;
	font-size: 12px;
	text-align: center;
	word-wrap: break-word;
	padding: 12pt 6pt 24pt;
}

.aboutHomeLink {
	text-decoration: none;
}
</style>

</head>

<body onload="init();" onclick="bodyOnclick();">
	
	<br>
	<div class="fileBrowserHeader" id="fileBrowserHeader">Shared content</div>
	<div class="fileBrowser" id="fileBrowser">
		<div class="dirExpander" id="rootExpander">
		
		<!-- Start shared content -->
